package com.ysd.lis.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ysd.common.Result;
import com.ysd.lis.entity.SysModeUrl;
import com.ysd.lis.mapper.sys.SysModeUrlMapper;
import com.ysd.lis.request.ModeUrlAddParam;
import com.ysd.lis.service.SysModeUrlService;
import org.apache.shiro.util.Assert;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author LiuQi
 * @since 2023-12-19
 */
@Service
public class SysModeUrlServiceImpl extends ServiceImpl<SysModeUrlMapper, SysModeUrl> implements SysModeUrlService {

    @Autowired
    public SysModeUrlMapper sysModeUrlMapper;

    @Override
    public Result getModeUrlListByMenuId(String menuId) {
        Assert.hasText(menuId, "menuId is not null");
        LambdaQueryWrapper<SysModeUrl> lambdaQueryWrapper = new LambdaQueryWrapper();
        lambdaQueryWrapper.eq(SysModeUrl::getMenuId, menuId);
        lambdaQueryWrapper.eq(SysModeUrl::getDelFlag, 0);
        List<SysModeUrl> sysModeUrls = sysModeUrlMapper.selectList(lambdaQueryWrapper);
        return Result.succ(1, "查询成功！", sysModeUrls);
    }

    @Override
    public Result addModeUrl(ModeUrlAddParam modeUrlAddParam) {
        SysModeUrl sysModeUrl = new SysModeUrl();
        BeanUtil.copyProperties(modeUrlAddParam, sysModeUrl);
        boolean save = this.save(sysModeUrl);
        if (save) {
            return Result.succ(1, "添加成功！", save);
        } else {
            return Result.fail("添加失败！");
        }
    }

    @Override
    public Result editModeUrl(ModeUrlAddParam modeUrlAddParam) {
        SysModeUrl sysModeUrl = new SysModeUrl();
        BeanUtil.copyProperties(modeUrlAddParam, sysModeUrl);
        boolean save = this.updateById(sysModeUrl);
        if (save) {
            return Result.succ(1, "编辑成功！", save);
        } else {
            return Result.fail("编辑失败！");
        }
    }
    @Override
    public Result deleteModeUrl(ModeUrlAddParam modeUrlAddParam) {
        SysModeUrl sysModeUrl = new SysModeUrl();
        BeanUtil.copyProperties(modeUrlAddParam, sysModeUrl);
        sysModeUrl.setDelFlag(1);
        boolean b = this.updateById(sysModeUrl);
        if (b) {
            return Result.succ(1, "删除成功！", b);
        } else {
            return Result.fail("删除失败！");
        }
    }
}
